﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;

namespace ChinaUnicom.Controls
{
    internal class Progressing
    {
        object locker = new object();

        ProgressBar bar;

        int counter = 0;

        public Progressing(ProgressBar bar)
        {
            this.bar = bar;
            InnerHide();
        }

        public void Show()
        {
            lock (locker)
            {
                if (counter == 0)
                {
                    bar.IsEnabled = true;
                    bar.IsIndeterminate = true;
                    bar.Visibility = System.Windows.Visibility.Visible;
                }

                counter++;
            }
        }

        public void Hide()
        {
            lock (locker)
            {
                counter--;
                if (counter <= 0)
                {
                    counter = 0;
                    InnerHide();
                }
            }
        }

        void InnerHide()
        {
            bar.Visibility = System.Windows.Visibility.Collapsed;
            bar.IsEnabled = false;
            bar.IsIndeterminate = false;
        }
    }
}
